import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/htmls',
    component: () => import('@/views/login/HtmlS'),
    hidden: true
  },

  //手机号验证
  {
    path: '/phoneLogin',
    component: () => import('@/views/login/PhoneLogin'),
    hidden: true
  },


  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/commentView',
    name: 'CommentView',
    component: () => import('@/views/comment/CommentView'),

  },

  {
    path: '/',
    component: Layout,
    redirect: '/userCenterView',
    meta: { title: '用户中心', icon: 'dashboard',roles: ['管理员','用户'] },
    children: [{
      path: 'userCenterView',
      name: 'UserCenterView',
      component: () => import('@/views/user/UserCenter'),
      meta: { title: '个人中心', icon: 'dashboard',roles: ['管理员','用户'] },
    },
      {
        path: 'userCenterEditView',
        name: 'UserCenterEditView',
        // hidden: true,
        component: () => import('@/views/user/UserCenterEditView'),
        meta: { title: '用户修改', icon: 'dashboard',roles: ['管理员','用户'] }
      },


    ]

  },





  {
    path: '/user',
    component: Layout,
    redirect: '/user/userView',
    meta: { title: '用户表', icon: 'dashboard' },
    children: [{
      path: 'userView',
      name: 'UserView',
      component: () => import('@/views/user/UserView'),
      meta: { title: '用户管理', icon: 'dashboard',roles: ['管理员'] }
    },
      {
        path: 'userEditView',
        name: 'UserEditView',
        hidden: true,
        component: () => import('@/views/user/UserEditView'),
        meta: { title: '用户修改', icon: 'dashboard',roles: ['管理员'] }
      },
      {
        path: 'userAddView',
        name: 'UserAddView',
        hidden: true,
        component: () => import('@/views/user/UserAddView'),
        meta: { title: '用户添加', icon: 'dashboard',roles: ['管理员'] }
      },

      //钱包
      {
        path: 'userMoneyView',
        name: 'UserMoneyView',
        component: () => import('@/views/user/UserMoney'),
        meta: { title: '用户余额', icon: 'dashboard',roles: ['管理员']}
      },
      {
        path: 'userMoneyEditView',
        name: 'UserMoneyEditView',
        hidden: true,
        component: () => import('@/views/user/UserMoneyEditView'),
        meta: { title: '修改用户余额', icon: 'dashboard',roles: ['管理员'] }
      },
      {
        path: 'rechargeView',
        name: 'RechargeView',
        component: () => import('@/views/user/RechargeView'),
        meta: { title: '充值界面', icon: 'dashboard',roles: ['用户'] }
      },


      {
        path: 'messagesView',
        name: 'MessagesView',
        component: () => import('@/views/user/MessagesView'),
        meta: { title: '消息中心', icon: 'dashboard',roles: ['管理员'] }
      },

    ]
  },
  {
    path: '/role',
    component: Layout,
    redirect: '/role/roleView',
    meta: { title: '角色表', icon: 'dashboard',roles: ['管理员']},
    children: [{
      path: 'roleView',
      name: 'RoleView',
      hidden: true,
      component: () => import('@/views/role/RoleView'),
      meta: { title: '角色管理', icon: 'dashboard' }
    },
      {
        path: 'roleEditView',
        name: 'RoleEditView',
        hidden: true,
        component: () => import('@/views/role/RoleEditView'),
        meta: { title: '角色修改', icon: 'dashboard' }
      },
      {
        path: 'roleAddView',
        name: 'RoleAddView',
        hidden: true,
        component: () => import('@/views/role/RoleAddView'),
        meta: { title: '添加角色', icon: 'dashboard' }
      },
    ]
  },
  {
    path: '/module',
    component: Layout,
    redirect: '/module/moduleView',
    meta: { title: '权限表', icon: 'dashboard',roles: ['管理员'] },
    children: [{
      path: 'moduleView',
      name: 'ModuleView',
      hidden: true,
      component: () => import('@/views/module/ModuleView'),
      meta: { title: '权限管理', icon: 'dashboard' }
    },
      {
        path: 'moduleEditView',
        name: 'ModuleEditView',
        hidden: true,
        component: () => import('@/views/module/ModuleEditView'),
        meta: { title: '权限修改', icon: 'dashboard' }
      },
      {
        path: 'moduleAddView',
        name: 'ModuleAddView',
        hidden: true,
        component: () => import('@/views/module/ModuleAddView'),
        meta: { title: '添加权限', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/novel',
    component: Layout,
    redirect: '/novel/novelView',
    meta: { title: '小说表', icon: 'dashboard' },
    children: [
      //小说管理
      {
        path: 'bookView',
        name: 'BookView',
        component: () => import('@/views/novel/BookView/BookView'),
        meta: { title: '小说管理', icon: 'dashboard' }
      },
      {
        path: 'bookEditView',
        name: 'BookEditView',
        hidden: true,
        component: () => import('@/views/novel/BookView/BookEditView'),
        meta: { title: '修改小说', icon: 'dashboard',roles: ['管理员'] }
      },
      {
        path: 'bookAddView',
        name: 'BookAddView',
        hidden: true,
        component: () => import('@/views/novel/BookView/BookAddView'),
        meta: { title: '添加小说', icon: 'dashboard',roles: ['管理员'] }
      },
      //分类管理
      {
        path: 'novelView',
        name: 'NovelView',
        component: () => import('@/views/novel/NovelView/NovelView'),
        meta: { title: '分类管理', icon: 'dashboard',roles: ['管理员'] }
      },
      {
        path: 'novelEditView',
        name: 'NovelEditView',
        hidden: true,
        component: () => import('@/views/novel/NovelView/NovelEditView'),
        meta: { title: '分类修改', icon: 'dashboard',roles: ['管理员'] }
      },
      {
        path: 'novelAddView',
        name: 'NovelAddView',
        hidden: true,
        component: () => import('@/views/novel/NovelView/NovelAddView'),
        meta: { title: '添加分类', icon: 'dashboard',roles: ['管理员'] }
      },
      //章节管理
      {
        path: 'novelChapterView',
        name: 'NovelChapterView',
        component: () => import('@/views/novel/NovelChaptersView/NovelChaptersView'),
        meta: { title: '章节管理', icon: 'dashboard',roles: ['管理员'] }
      },
      {
        path: 'novelChapterEditView',
        name: 'NovelChapterEditView',
        hidden: true,
        component: () => import('@/views/novel/NovelChaptersView/NovelChaptersEditView'),
        meta: { title: '章节修改', icon: 'dashboard',roles: ['管理员'] }
      },
      {
        path: 'novelChapterAddView',
        name: 'NovelChapterAddView',
        hidden: true,
        component: () => import('@/views/novel/NovelChaptersView/NovelChaptersAddView'),
        meta: { title: '添加章节', icon: 'dashboard',roles: ['管理员'] }
      },

      //书架管理
      {
        path: 'bookShelfView',
        name: 'BookShelfView',
        // hidden: true,
        component: () => import('@/views/novel/BookShelfView/BookShelfView'),
        meta: { title: '我的书架', icon: 'dashboard',roles: ['用户'] }
      },

      //书籍详情
      {
        path: 'bookShelfViewDetails',
        name: 'BookShelfViewDetails',
        hidden: true,
        component: () => import('@/views/novel/BookShelfView/BookShelfViewDetails'),
        meta: { title: '书籍详情', icon: 'dashboard',roles: ['用户'] }
      },



      //order订单管理
      //订单管理
      {
        path: 'orderView',
        name: 'OrderView',
        // hidden: true,
        component: () => import('@/views/novel/OrderView/OrderView'),
        meta: { title: '订单管理', icon: 'dashboard',roles: ['用户'] }
      },
    ]
  },




  // {
  //   path: '/form',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Form',
  //       component: () => import('@/views/form/index'),
  //       meta: { title: 'Form', icon: 'form' }
  //     }
  //   ]
  // },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
